package com.hospital.repository;

import com.hospital.model.Patient;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.hospital.model.Appointment;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;

@Repository
public class PatientRepository {
    private List<Patient> patients = new ArrayList<>();
    private Long nextId = 1L;

    public Patient save(Patient patient) {
        if (patient.getId() == null) {
            patient.setId(nextId++);
        }
        patients.add(patient);
        return patient;
    }

    public Optional<Patient> findById(Long id) {
        return patients.stream().filter(p -> p.getId().equals(id)).findFirst();
    }

    public List<Patient> findAll() {
        return new ArrayList<>(patients);
    }
}